

import java.math.BigDecimal;
import java.math.MathContext;


/**
 * @author navas
 *
 */
public class TimesBinExpr extends BinExpr {

	public TimesBinExpr(Expr lExpr, Expr rExpr) {
		super(lExpr, rExpr);

	}
	public BigDecimal evaluate(Env env) {

		BigDecimal value = leftExpr.evaluate(env).multiply(rightExpr.evaluate(env), MathContext.DECIMAL128);

		return value;


	}

	public static TimesBinExpr _(Expr lExpr, Expr rExpr){
		return new TimesBinExpr(lExpr, rExpr);
	}
	@Override
	public String toString() {
		String leftExprTmp = leftExpr.toString();
		String rightExprTmp = "("+rightExpr.toString()+")";

		if(leftExpr.isPlusBinExpr() || leftExpr.isMinusBinExpr())
			leftExprTmp = "("+leftExprTmp+")";
		
		if(rightExpr.isUnExpr() || rightExpr.isNum() || rightExpr.isId())
			rightExprTmp = rightExpr.toString();

		return leftExprTmp+" * "+rightExprTmp;
	}
	
	@Override
	public boolean isUnExpr() {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public boolean isAssignExpr() {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public boolean isPlusBinExpr() {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public boolean isMinusBinExpr() {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public boolean isTimesBinExpr() {
		// TODO Auto-generated method stub
		return true;
	}
	@Override
	public boolean isDivideBinExpr() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isNum() {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public boolean isId() {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public boolean isSeqExpr() {
		// TODO Auto-generated method stub
		return false;
	}
}
